Skip to content

fix: use CORS-friendly public RPCs as fallbacks when no PUBLIC_RPC_* env vars are set#445

Merged
gabitoesmiapodo merged 6 commits intodevelopfrom
fix/441
Apr 7, 2026
Merged

fix: use CORS-friendly public RPCs as fallbacks when no PUBLIC_RPC_* env vars are set#445
gabitoesmiapodo merged 6 commits intodevelopfrom
fix/441

Conversation

@gabitoesmiapodo
Copy link
Copy Markdown
Collaborator

Summary

When PUBLIC_RPC_* env vars are not configured, viem falls back to chain-built-in default RPCs (e.g. eth.merkle.io for mainnet) which do not set Access-Control-Allow-Origin headers. This breaks all on-chain features from any browser origin, including localhost and *.vercel.app preview deployments.

Closes #441

Changes

  • src/lib/networks.config.ts: add CORS-friendly publicnode.com fallback URLs for all 6 configured chains via || in each http() call
  • .env.example: update RPC comment to reflect new default behavior

Acceptance criteria

  • App loads and RPC calls succeed without any PUBLIC_RPC_* env vars set
  • No CORS errors in the browser console when running pnpm dev without RPC env vars
  • When PUBLIC_RPC_* is set, the custom URL is used (not the fallback)

Test plan

  • pnpm lint -- passes
  • pnpm test -- 170 tests pass across 32 test files
  • Manual: run pnpm dev without any PUBLIC_RPC_* in .env.local, confirm no CORS errors from eth.merkle.io

Checklist

  • Self-reviewed my own diff
  • Tests added or updated
  • Docs updated (if applicable)
  • No unrelated changes bundled in

…env vars are set

When PUBLIC_RPC_* env vars are not configured, viem falls back to chain
defaults (e.g. eth.merkle.io for mainnet) which block cross-origin requests.
Replace with publicnode.com fallbacks that set Access-Control-Allow-Origin: *.

Closes #441
Copilot AI review requested due to automatic review settings April 6, 2026 20:05
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
components.dappbooster Ready Ready Preview, Comment Apr 7, 2026 1:50pm
demo.dappbooster Ready Ready Preview, Comment Apr 7, 2026 1:50pm
docs.dappbooster Ready Ready Preview, Comment Apr 7, 2026 1:50pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the app’s viem/wagmi transport configuration so that when PUBLIC_RPC_* env vars are unset, the app uses CORS-friendly fallback RPC endpoints (publicnode.com) instead of viem’s chain-default public RPCs that can fail CORS in browsers (notably on localhost and Vercel previews).

Changes:

  • Added publicnode.com fallback URLs for the currently configured chains in transports when PUBLIC_RPC_* is unset.
  • Updated .env.example RPC comment to reflect the new fallback behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lib/networks.config.ts Adds publicnode.com URLs as fallbacks for the configured chain transports when env RPCs are missing.
.env.example Updates the RPC section comment to describe the new default behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@fernandomg fernandomg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go with dRPC

@gabitoesmiapodo
Copy link
Copy Markdown
Collaborator Author

I would go with dRPC

@fernandomg that looks fine, but I researched a bit and:

  • Requires an API key. We'd need to add the env var and who knows what to dAppBooster, and it would add extra friction for potential users (they'd have to register, get the API key, add it to .env).
  • It's rate limited. Rates are high enough, but you never know.

In any case, it's something we can evaluate in a different issue / PR. This one solved what intended to solve.

@gabitoesmiapodo gabitoesmiapodo merged commit 466dd00 into develop Apr 7, 2026
8 checks passed
@gabitoesmiapodo gabitoesmiapodo deleted the fix/441 branch April 7, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CORS errors on Vercel preview deployments when no PUBLIC_RPC_* env vars are configured

3 participants